package com.zhiwei.tool;

import com.zhiwei.mapper.UserMapper;
import com.zhiwei.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class UserMsgUtil {

    private static UserMapper userMapper;

    @Autowired
    public  void setRedisTemplate(UserMapper userMapper) {
        UserMsgUtil.userMapper = userMapper;
    }

    public static int addMsgNum(Integer userId){
        User user = userMapper.selectById(userId);
        user.setMsgNum(user.getMsgNum()+1);
        return userMapper.updateById(user);
    }
    public static int cleanMsgNum(Integer userId){
        log.info("清空信息"+userId);
        User user = userMapper.selectById(userId);
        user.setMsgNum(0);
        return userMapper.updateById(user);
    }
}
